using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;

namespace Coldairarrow.Util.Other
{
  public class GetWxMapInfoHelper
  {
    public async Task<string> GetMapAddressInfo(string lat, string lng)
    {
      string wxMapAPi = ConfigurationUtil.GetSection("WxMapAPI");
      string address = "";
      if (!lat.IsNullOrEmpty() && !lng.IsNullOrEmpty())
      {
        var client = new HttpClient();

        var urlData = wxMapAPi + "&location="+lat + ","+lng+"&get_poi=1";

        //发送Get请求
        var responseString = await client.GetStringAsync(urlData);
        if (!responseString.IsNullOrEmpty())
        {
          var ajaxResult = JsonSerializer.Deserialize<AddressData>(responseString);
          if (ajaxResult.status == 0)
          {
            address = ajaxResult.result.address;
          }
        }
      }

      return address;
    }
  }


  public class AddressData
  { 
    public int status { get; set; }

    public string message { get; set; }

    public AddressInfo result { get; set; }
  }

  public class AddressInfo {
    public string address { get; set; }
  }
}
